//
//  WaitForFetchViewController.m
//  atXiaoGeBClient
//
//  Created by Linyu Niu on 20/04/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "WaitForFetchViewController.h"

#import <MAMapKit/MAMapView.h>
#import <AMapLocationKit/AMapLocationManager.h>

@interface WaitForFetchViewController ()<MAMapViewDelegate,AMapLocationManagerDelegate>
{
    MAMapView * mapView;
    AMapLocationManager * locationManager;
    UIView * navView;
}
@end

@implementation WaitForFetchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initMap];
    
    __weak WaitForFetchViewController * weakSelf = self;
    navView = [[CTMediator sharedInstance] navgationHeadViewInTargetView:self.view params:[NSDictionary dictionaryWithObjectsAndKeys:@"待取件详情",@"title", nil] leftAction:^(UIButton * sender){
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } rightAction:nil];
    [self addStatusViewBelowView:navView];
    
}
-(void)addStatusViewBelowView:(UIView *)view{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, view.frame.origin.y + view.frame.size.height, self.view.frame.size.width, 0)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    UIImageView * timeImgView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 60, 60)];
    timeImgView.layer.cornerRadius = 30.0;
    timeImgView.layer.masksToBounds = YES;
    timeImgView.backgroundColor = [UIColor blueColor];
    [bgView addSubview:timeImgView];
    
    UILabel * nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(timeImgView.frame.origin.x + timeImgView.frame.size.width + 5, timeImgView.frame.origin.y, 200, 20)];
    nameLabel.font = [UIFont systemFontOfSize:14];
    nameLabel.textColor = [UIColor colorWithRed:51.0 / 255.0 green:51.0 / 255.0 blue:51.0 / 255.0 alpha:1.0];
    [bgView addSubview:nameLabel];
    
    UILabel * addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(nameLabel.frame.origin.x, nameLabel.frame.origin.y + nameLabel.frame.size.height + 10, bgView.frame.size.width - timeImgView.frame.origin.x - timeImgView.frame.size.width - 20, nameLabel.frame.size.height)];
    addressLabel.font = [UIFont systemFontOfSize:14];
    addressLabel.textColor = [UIColor colorWithRed:148.0 / 255.0 green:148.0 / 255.0 blue:148.0 / 255.0 alpha:1.0];
    
    [bgView addSubview:addressLabel];
    
    
    UILabel * createTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(nameLabel.frame.origin.x, addressLabel.frame.origin.y + addressLabel.frame.size.height + 10, addressLabel.frame.size.width - timeImgView.frame.origin.x, nameLabel.frame.size.height)];
    createTimeLabel.font = [UIFont systemFontOfSize:14];
    createTimeLabel.textColor = [UIColor colorWithRed:148.0 / 255.0 green:148.0 / 255.0 blue:148.0 / 255.0 alpha:1.0];
    
    [bgView addSubview:createTimeLabel];
    
    
    UILabel * receiveTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(nameLabel.frame.origin.x, createTimeLabel.frame.origin.y + createTimeLabel.frame.size.height + 10, addressLabel.frame.size.width - timeImgView.frame.origin.x, nameLabel.frame.size.height)];
    receiveTimeLabel.font = [UIFont systemFontOfSize:14];
    receiveTimeLabel.textColor = [UIColor colorWithRed:148.0 / 255.0 green:148.0 / 255.0 blue:148.0 / 255.0 alpha:1.0];
    
    [bgView addSubview:receiveTimeLabel];
    
    
    UIButton * phoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    phoneButton.frame = CGRectMake(bgView.frame.size.width - timeImgView.frame.size.width - timeImgView.frame.origin.x, timeImgView.frame.origin.y, timeImgView.frame.size.width, timeImgView.frame.size.height);
    phoneButton.layer.cornerRadius = phoneButton.frame.size.height / 2;
    phoneButton.backgroundColor = [UIColor blueColor];
    [bgView addSubview:phoneButton];
    
#if kDevelopment
    addressLabel.text = @"金城社区东花市里20号楼18楼";
    createTimeLabel.text = @"发单时间：09-09 16：39";
    receiveTimeLabel.text = @"接单时间：09-09 16：39";
    nameLabel.text = @"张先生";
#endif
    
    bgView.frame = CGRectMake(bgView.frame.origin.x, bgView.frame.origin.y, bgView.frame.size.width, receiveTimeLabel.frame.size.height + receiveTimeLabel.frame.origin.y + timeImgView.frame.origin.y);
}


-(void)initMap{
    
    locationManager = [[AMapLocationManager alloc]init];
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    
    mapView = [[MAMapView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:mapView];
    
    
    
    //设置代理
    mapView.delegate = self;
    
    /*高德地图涉及到的一些属性*/
    //1.设置是否显示底层的建筑名称标注
    mapView.showsLabels = YES;
    //2.设置地图的类型,分为卫星地图，标准地图和夜景地图
    mapView.mapType = MAMapTypeStandard;
    //3.设置是否显示交通状况
    mapView.showTraffic = YES;
    //4.设置显示本人的位置，结合定位功能使用
    
    //5.设置地图logo，默认字样是“高德地图”，用logoCenter来设置logo的位置
    mapView.logoCenter = CGPointMake(self.view.frame.size.width - 100, self.view.frame.size.height - 50);
    //6.设置指南针compass，默认是开启状态，大小是定值，显示在地图的右上角
    //    mapView.showsCompass = YES;
    //    mapView.compassOrigin = self.view.center;
    //7.设置比例尺scale，默认显示在地图的左上角
    //    mapView.showsScale = YES;
    //    mapView.scaleOrigin = CGPointMake(100, 100);
    //8.设置地图手势
    mapView.zoomEnabled = YES;//开启地图手势
    [mapView setZoomLevel:15 animated:YES];
    //9.设置是否开启滑动手势
    mapView.scrollEnabled = YES;
    //10.设置是否开启旋转手势
    mapView.rotateEnabled = YES;
    //11.设置是否开启倾斜手势
    mapView.rotateCameraEnabled = YES;
    [self performSelector:@selector(setMapTrackingMode) withObject:nil afterDelay:0.8];
}

-(void)setMapTrackingMode{
    mapView.showsUserLocation = YES;
    mapView.userTrackingMode = MAUserTrackingModeFollow;
}

@end
